using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Connection;

namespace MingProject
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Configuration cfg = new Configuration();
            //cfg.AddAssembly("Ming.WaterFactory.DemoClsLib");
            //            System.Reflection.Assembly ass = Assembly.LoadFrom("Ming.WaterFactory.D");
            //cfg.AddXmlFile("TaskType.hbm.xml");
            //cfg.AddXmlFile("Task.hbm.xml");
            cfg.AddAssembly("MingProject");

            //cfg.AddDirectory(new System.IO.DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory));
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();
            TaskType pt = new TaskType();
            pt.ID = 2;
            pt.Name = "MyTask";
            //session.Save(pt);
            Task tt = new Task();
            //tt.ID = 3;
            tt.TaskType = pt;
            
            tt.ParTask = null;
            ProjectInfo pi=new ProjectInfo();
            pi.ID=2;
            tt.PNo =pi ;
            tt.Name = "taskname";
            tt.WBS = "1.1";
            session.Save(tt);
            // Tell NHibernate that this object should be saved

            
            // commit all of the changes to the DB and close the ISession
            transaction.Commit();
            session.Close();
            MessageBox.Show("OK");
        }
    }
}